package game.controller
{
	import flash.utils.getTimer;
	import game.constants.ApplicationNotification;
	import game.model.building.BuildingConfigProxy;
	import game.model.building.BuildingProxy;
	import game.model.building.vo.BuildingConfigVO;
	import game.model.building.vo.BuildingVO;
	import game.model.player.PlayerProxy;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Thot
	 */
	
	public class StartBuildingEvolutionCommand extends SimpleCommand
	{
		override public function execute( notification:INotification ):void
		{
			var playerProxy:PlayerProxy = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
			var proxy:BuildingProxy = facade.retrieveProxy(BuildingProxy.NAME) as BuildingProxy;
			var buildVO:BuildingVO = proxy.getBuildBy("name", notification.getBody().name);
			
			if ( 
				playerProxy.currentPlayer.gold < buildVO.costGold || 
				playerProxy.currentPlayer.mana < buildVO.costMana || 
				playerProxy.currentPlayer.gems < buildVO.costGems ||
				buildVO.isIncreasing()
			)
			{
				sendNotification(ApplicationNotification.CANNOT_BUY);
				return;
			}
			
			playerProxy.currentPlayer.gold -= buildVO.costGold;
			playerProxy.currentPlayer.mana -= buildVO.costMana;
			playerProxy.currentPlayer.gems -= buildVO.costGems;
			
			buildVO.startIncrease();
		}
	}

}